Option Explicit

Private Const TEST_TABLE_NAME As String = "table1"
Private Const TEST_POINT As String = "."
Private Const TEST_COL_NAME As String = "col1"
Private Const TEST_SHARE_LINE_COMMENT As String = "--aaaaaa"
Private Const TEST_SINGLE_LINE_COMMENT As String = "--bbbbb"

' ======================================================================
' 执行所有测试用例
' ======================================================================
Public Sub test_all_case()

    ' ==================================================
    ' ISqlFormatterCondition 接口实现测试
    ' ==================================================
    ' 测试: 添加当前条件的逻辑运算符
    test_ISqlFormatterCondition_setLogicOperator

    ' 测试: 设置条件运算符
    test_ISqlFormatterCondition_setConditionOperator

    ' 测试: 返回对齐的长度
    test_ISqlFormatterAlignmentElem_getAlignmentSize

    ' 测试: 设置对齐空格长度
    test_ISqlFormatterAlignmentElem_setAlignmentSpaceCount

    ' 测试: 从条件的左侧元素获取条件组
    test_ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromLeftElem

    ' 测试: 从条件的右侧元素获取条件组
    test_ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromRightElem

    ' 测试: 设置当前条件不是整个区域中的唯一一个条件
    test_ISqlFormatterCondition_setNotOnlyOneCondition

    ' ==================================================
    ' ISqlFormatterElem 接口实现测试
    ' ==================================================
    ' 测试: addComponent 方法
    test_ISqlFormatterElem_addComponent
    ' 测试: addComponentToFirst 方法
    test_ISqlFormatterElem_addComponentToFirst
    ' 测试: canAddComponentToFirst 方法
    test_ISqlFormatterElem_canAddComponentToFirst
    ' 测试: getAlignmentElemGroups 方法
    test_ISqlFormatterElem_getAlignmentElemGroups
    ' 测试: setElemNestCount 方法
    test_ISqlFormatterElem_setElemNestCount
    ' 测试: setPrefixSpaceCount 方法
    test_ISqlFormatterElem_setPrefixSpaceCount
    ' 测试: hasBoundaryParenthesis 方法
    test_ISqlFormatterElem_hasBoundaryParenthesis
    ' 测试: addBoundaryLeftParenthesis 方法
    test_ISqlFormatterElem_addBoundaryLeftParenthesis
    ' 测试: addBoundaryRightParenthesis 方法
    test_ISqlFormatterElem_addBoundaryRightParenthesis
    ' 测试: getType 方法
    test_ISqlFormatterElem_getType
    ' 测试: isComment 方法
    test_ISqlFormatterElem_isComment
    ' 测试: isShareLineComment 方法
    test_ISqlFormatterElem_isShareLineComment
    ' 测试: isSingleLineComment 方法
    test_ISqlFormatterElem_isSingleLineComment
    ' 测试: isEndsWithComment 方法
    test_ISqlFormatterElem_isEndsWithComment
    ' 测试: isMultiLine 方法
    test_ISqlFormatterElem_isMultiLine
    ' 测试: toString + toStringArray 方法
    test_ISqlFormatterElem_toString_toStringArray
End Sub

' ======================================================================
' 测试通用处理
' ======================================================================
' 获取 Not <= 条件运算符
' 获取一个条件运算符: <=
Private Function getNotLeConditionOperator() As ISqlFormatterElem
    Dim result As SqlFormatterTokenGroup
    Set result = New SqlFormatterTokenGroup

    result.ISqlFormatterElem_addComponent getNotToken
    result.ISqlFormatterElem_addComponent getLeConditionOperator
    result.setType SqlTokenType.OPERA_LE

    Set getNotLeConditionOperator = result
End Function

' 创建和前一个元素在同一行的注释
Private Function createShareLineCommentToken(ByRef v As String) As SqlToken
    Set createShareLineCommentToken = New SqlToken
    createShareLineCommentToken.Init v, SqlTokenType.SHARE_LINE_COMMENT
End Function

' 获取一个单行的注释
Private Function createSingleLineCommentToken(ByRef v As String) As SqlToken
    Set createSingleLineCommentToken = New SqlToken
    createSingleLineCommentToken.Init v, SqlTokenType.SINGLE_LINE_COMMENT
End Function

' 获取 Not
Private Function getNotToken() As SqlToken
    Set getNotToken = New SqlToken
    getNotToken.Init "not", SqlTokenType.KEY_NOT
End Function

' 获取逻辑运算符: and
Private Function getAndToken() As SqlToken
    Set getAndToken = New SqlToken
    getAndToken.Init "and", SqlTokenType.KEY_AND
End Function

' 获取逻辑运算符: or
Private Function getOrToken() As SqlToken
    Set getOrToken = New SqlToken
    getOrToken.Init "or", SqlTokenType.KEY_OR
End Function

' 获取一个条件运算符: <=
Private Function getLeConditionOperator() As SqlToken
    Set getLeConditionOperator = New SqlToken
    getLeConditionOperator.Init "<=", SqlTokenType.OPERA_LE
End Function

' 获取表名 token
Private Function getTableNameToken() As SqlToken
    Set getTableNameToken = New SqlToken
    getTableNameToken.Init TEST_TABLE_NAME, SqlTokenType.STR_NAME
End Function

' 获取一个任意名称的 STR_NAME token
Private Function getStrNameToken(ByRef s As String) As SqlToken
    Set getStrNameToken = New SqlToken
    getStrNameToken.Init s, SqlTokenType.STR_NAME
End Function

' 获取 [.] token
Private Function getPointToken() As SqlToken
    Set getPointToken = New SqlToken
    getPointToken.Init TEST_POINT, SqlTokenType.POINT
End Function

' 获取列名 token
Private Function getColNameToken() As SqlToken
    Set getColNameToken = New SqlToken
    getColNameToken.Init TEST_COL_NAME, SqlTokenType.STR_NAME
End Function

' 获取和前一个元素在同一行的注释
Private Function getShareLineCommentToken() As ISqlFormatterElem
    Dim result As SqlToken
    Set result = New SqlToken
    result.Init TEST_SHARE_LINE_COMMENT, SqlTokenType.SHARE_LINE_COMMENT

    Set getShareLineCommentToken = result
End Function

' 获取一个单行的注释
Private Function getSingleLineCommentToken() As ISqlFormatterElem
    Dim result As SqlToken
    Set result = New SqlToken
    result.Init TEST_SINGLE_LINE_COMMENT, SqlTokenType.SINGLE_LINE_COMMENT

    Set getSingleLineCommentToken = result
End Function

' 获取一个逗号的元素
Private Function getCommaToken() As SqlToken
    Set getCommaToken = New SqlToken
    getCommaToken.Init ",", SqlTokenType.COMMA
End Function

' 获取一个没有边界括号的多行元素
' 多行连接的结果:
' col1 & ","
' col2
Private Function getMultiLineElemNoParenthesis() As ISqlFormatterElem
    Dim g As SqlFormatterCommaDeliMultiElem
    Set g = New SqlFormatterCommaDeliMultiElem

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' 1. 增加一个单行元素
    elem.addComponent getStrNameToken("col1")

    ' 2. 手动设置为多行元素，仍然是单行
    g.setNeedMultiLineWhenHasComma True

    ' 3. 在末尾添加一个逗号元素，仍然是单行的
    elem.addComponent getCommaToken

    ' 4. 再增加一个单行元素，变成多行的
    elem.addComponent getStrNameToken("col2")

    Set getMultiLineElemNoParenthesis = elem
End Function

' 获取一个多行的元素--包含边界括号
' 多行连接的结果:
' "("
' "    " & TEST_TABLE_NAME & ","
' "    " & TEST_TABLE_NAME
' ")"
Private Function getMultiLineElemWithBoundaryParenthesis() As ISqlFormatterElem
    Dim g As SqlFormatterCommaDeliMultiElem
    Set g = New SqlFormatterCommaDeliMultiElem

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 单行变多行的测试
    ' ==============================
    ' 1. 增加一个单行元素
    elem.addComponent getTableNameToken

    ' 2. 手动设置为多行元素，仍然是单行
    g.setNeedMultiLineWhenHasComma True

    ' 3. 在末尾添加一个逗号元素，仍然是单行的
    elem.addComponent getCommaToken

    ' 4. 设置边界括号后，仍然是单行的
    elem.addBoundaryLeftParenthesis
    elem.addBoundaryRightParenthesis

    ' 5. 再增加一个单行元素，变成多行的
    elem.addComponent getTableNameToken

    Set getMultiLineElemWithBoundaryParenthesis = elem
End Function

' ======================================================================
' ISqlFormatterCondition 接口实现测试
' ======================================================================
' 测试: 添加当前条件的逻辑运算符
Private Sub test_ISqlFormatterCondition_setLogicOperator()
    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef
    Dim g As SqlFormatterTwoElemCondition

    ' ==============================
    ' 1. 单行 + 无逻辑运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 <= x2"

    ' ==============================
    ' 2. 多行 + 无逻辑运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素 (多行元素)
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素 (单行元素)
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<= x2"

    ' ==============================
    ' 3. 单行 + and 逻辑运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置 and
    g.ISqlFormatterCondition_setLogicOperator getAndToken
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterElem_toString(config) = "and x1 <= x2"

    ' ==============================
    ' 4. 单行 + or 逻辑运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置 and
    g.ISqlFormatterCondition_setLogicOperator getOrToken
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterElem_toString(config) = "or  x1 <= x2"

    ' ==============================
    ' 5. 多行 + and 逻辑运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置 and
    g.ISqlFormatterCondition_setLogicOperator getAndToken
    ' 设置第一个元素 (多行元素)
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素 (单行元素)
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "and col1,"
    Debug.Assert strArr.Item(1) = "    col2"
    Debug.Assert strArr.Item(2) = "    <= x2"

    ' ==============================
    ' 6. 多行 + or 逻辑运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置 and
    g.ISqlFormatterCondition_setLogicOperator getOrToken
    ' 设置第一个元素 (多行元素)
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素 (单行元素)
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "or  col1,"
    Debug.Assert strArr.Item(1) = "    col2"
    Debug.Assert strArr.Item(2) = "    <= x2"
End Sub

' 测试: 设置条件运算符
Private Sub test_ISqlFormatterCondition_setConditionOperator()
    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef
    Dim g As SqlFormatterTwoElemCondition

    ' ==============================
    ' 1. 单行 + 无条件运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1"

    ' ==============================
    ' 2. 单行 + 有条件运算符
    ' ==============================
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 <= x2"

    ' ==============================
    ' 3. 多行 + 无条件运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素 (多行)
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"

    ' ==============================
    ' 4. 多行 + 有条件运算符
    ' ==============================
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<= x2"

    ' ==============================
    ' 5. 单行 + 包含 Not 的条件运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getNotLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 not <= x2"

End Sub

' 测试: 返回对齐的长度
Private Sub test_ISqlFormatterAlignmentElem_getAlignmentSize()
    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim g As SqlFormatterTwoElemCondition

    ' ==============================
    ' 1. 初始值测试: -1
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = -1
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = -1 ' 重复测试

    ' ==============================
    ' 2. 如果条件运算符不存在: -1
    ' ==============================
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = -1
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = -1 ' 重复测试

    ' ==============================
    ' 3. 如果左侧元素是多行: -1
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素 (多行元素)
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素 (单行元素)
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = -1
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = -1 ' 重复测试

    ' ==============================
    ' 4. 单行元素 + 条件运算符右侧对齐 + 没有开头的填充空格 + 不设置前缀空格数量
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 5
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 5 ' 重复测试

    ' ==============================
    ' 5. 单行元素 + 条件运算符右侧对齐 + 有开头的填充空格 + 不设置前缀空格数量
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")
    g.ISqlFormatterCondition_setNotOnlyOneCondition

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 9 ' 4 + 5
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 9 ' 重复测试

    ' ==============================
    ' 6. 单行元素 + 条件运算符右侧对齐 + 没有开头的填充空格 + 设置前缀空格数量
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")
    g.ISqlFormatterElem_setPrefixSpaceCount 20, config

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 25 ' 20 + 5
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 25 ' 重复测试

    ' ==============================
    ' 7. 单行元素 + 条件运算符右侧对齐 + 有开头的填充空格 + 设置前缀空格数量
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")
    g.ISqlFormatterCondition_setNotOnlyOneCondition
    g.ISqlFormatterElem_setPrefixSpaceCount 20, config

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 29 ' 20 + 4 + 5
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 29 ' 重复测试

    ' ==============================
    ' 8. 单行元素 + 条件运算符左侧对齐 + 没有开头的填充空格 + 不设置前缀空格数量
    ' ==============================
    config.alignmentPosition = SqlAlignmentPosition.OPERATOR_LEFT

    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 3
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 3 ' 重复测试

    ' ==============================
    ' 9. 单行元素 + 条件运算符左侧对齐 + 有开头的填充空格 + 不设置前缀空格数量
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")
    g.ISqlFormatterCondition_setNotOnlyOneCondition

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 7 ' 4 + 3
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 7 ' 重复测试

    ' ==============================
    ' 10. 单行元素 + 条件运算符左侧对齐 + 没有开头的填充空格 + 设置前缀空格数量
    ' ==============================
    config.alignmentPosition = SqlAlignmentPosition.OPERATOR_LEFT

    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")
    g.ISqlFormatterElem_setPrefixSpaceCount 20, config

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 23 ' 20 + 3
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 23 ' 重复测试

    ' ==============================
    ' 11. 单行元素 + 条件运算符左侧对齐 + 有开头的填充空格 + 设置前缀空格数量
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")
    g.ISqlFormatterCondition_setNotOnlyOneCondition
    g.ISqlFormatterElem_setPrefixSpaceCount 20, config

    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 27 ' 20 + 4 + 3
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 27 ' 重复测试

End Sub

' 测试: 设置对齐空格长度
Private Sub test_ISqlFormatterAlignmentElem_setAlignmentSpaceCount()

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim g As SqlFormatterTwoElemCondition

    Dim strArr As IPrimitiveArrayRef
    Dim multiCondi As SqlFormatterTwoElemCondition

    ' ==============================
    ' 1. 只有一个单行元素
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")

    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 0, config
    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1"

    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 5, config
    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1"

    ' ==============================
    ' 2. 只有一个多行元素
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis

    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"

    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 5, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"

    ' ==============================
    ' 3. 两个单行元素
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 0, config
    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 <= x2"

    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 5, config
    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1      <= x2"

    ' ==============================
    ' 4. 单行元素 + 多行元素
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis

    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "x1 <= col1,"
    Debug.Assert strArr.Item(1) = "      col2"

    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 5, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "x1      <= col1,"
    Debug.Assert strArr.Item(1) = "           col2"

    ' ==============================
    ' 5. 单行元素 + 多行条件元素 + 需要开头的填充空格，并检查多行条件的对齐长度是否添加了当前对齐空格的长度
    '    没有对齐长度
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个多行条件元素，条件的内容是:
    ' col1,
    ' col2
    ' <= x2
    Set multiCondi = New SqlFormatterTwoElemCondition
    multiCondi.ISqlFormatterElem_addComponent getStrNameToken("x2")
    multiCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiCondi.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    g.ISqlFormatterElem_addComponent multiCondi

    g.ISqlFormatterCondition_setNotOnlyOneCondition

    ' 没有对齐长度
    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    '                                            V 下面要获取的是到这里的长度
    Debug.Assert strArr.Item(0) = "    x1 <= x2 <= col1,"
    Debug.Assert strArr.Item(1) = "                col2"

    Debug.Assert multiCondi.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 15

    ' ==============================
    ' 6. 单行元素 + 多行条件元素 + 需要开头的填充空格，并检查多行条件的对齐长度是否添加了当前对齐空格的长度
    '    对齐长度 = 5
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个多行条件元素，条件的内容是:
    ' col1,
    ' col2
    ' <= x2
    Set multiCondi = New SqlFormatterTwoElemCondition
    multiCondi.ISqlFormatterElem_addComponent getStrNameToken("x2")
    multiCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiCondi.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    g.ISqlFormatterElem_addComponent multiCondi

    g.ISqlFormatterCondition_setNotOnlyOneCondition

    ' 对齐长度 = 5
    g.ISqlFormatterAlignmentElem_setAlignmentSpaceCount 5, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    '                                                 V 下面要获取的是到这里的长度
    Debug.Assert strArr.Item(0) = "    x1      <= x2 <= col1,"
    Debug.Assert strArr.Item(1) = "                     col2"

    Debug.Assert multiCondi.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 20
End Sub

' 测试: 从条件的左侧元素获取条件组
Private Sub test_ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromLeftElem()
    ' IObjArrayRef<IObjArrayRef<ISqlFormatterCondition>>
    Dim groups As IObjArrayRef
    Dim group As IObjArrayRef

    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    ' 一个多行条件
    Dim multiCondi As SqlFormatterTwoElemCondition
    Set multiCondi = New SqlFormatterTwoElemCondition
    multiCondi.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiCondi.ISqlFormatterElem_addComponent getStrNameToken("x2")

    ' 第二个多行条件
    Dim multiCondi2 As SqlFormatterTwoElemCondition
    Set multiCondi2 = New SqlFormatterTwoElemCondition
    multiCondi2.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiCondi2.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiCondi2.ISqlFormatterElem_addComponent getStrNameToken("x2")

    ' ==============================
    ' 1. 不设置元素
    ' ==============================
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromLeftElem Is Nothing

    ' ==============================
    ' 2. 设置一个单行元素
    ' ==============================
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromLeftElem Is Nothing

    ' ==============================
    ' 3. 设置一个多行元素
    ' ==============================
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromLeftElem Is Nothing

    ' ==============================
    ' 4. 设置一个条件元素
    ' ==============================
    g.ISqlFormatterElem_addComponent multiCondi
    Set groups = g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromLeftElem
    Debug.Assert groups.Count = 1
    Set group = groups.Item(0)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is multiCondi

    ' ==============================
    ' 5. 设置第二个条件元素
    ' ==============================
    g.ISqlFormatterElem_addComponent multiCondi2
    Set groups = g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromLeftElem
    Debug.Assert groups.Count = 2
    Set group = groups.Item(0)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is multiCondi
    Set group = groups.Item(1)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is multiCondi2
End Sub

' 测试: 从条件的右侧元素获取条件组
Private Sub test_ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromRightElem()

    ' IObjArrayRef<IObjArrayRef<ISqlFormatterCondition>>
    Dim groups As IObjArrayRef
    Dim group As IObjArrayRef

    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    ' 一个多行条件
    Dim multiCondi As SqlFormatterTwoElemCondition
    Set multiCondi = New SqlFormatterTwoElemCondition
    multiCondi.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiCondi.ISqlFormatterElem_addComponent getStrNameToken("x2")

    ' 第二个多行条件
    Dim multiCondi2 As SqlFormatterTwoElemCondition
    Set multiCondi2 = New SqlFormatterTwoElemCondition
    multiCondi2.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiCondi2.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiCondi2.ISqlFormatterElem_addComponent getStrNameToken("x2")

    ' ==============================
    ' 1. 不设置元素
    ' ==============================
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromRightElem Is Nothing

    ' ==============================
    ' 2. 设置一个单行元素
    ' ==============================
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("y1")
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromRightElem Is Nothing

    ' ==============================
    ' 3. 设置一个多行元素
    ' ==============================
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromRightElem Is Nothing

    ' ==============================
    ' 4. 设置一个条件元素
    ' ==============================
    g.ISqlFormatterElem_addComponent multiCondi
    Set groups = g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromRightElem
    Debug.Assert groups.Count = 1
    Set group = groups.Item(0)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is multiCondi

    ' ==============================
    ' 5. 设置第二个条件元素
    ' ==============================
    g.ISqlFormatterElem_addComponent multiCondi2
    Set groups = g.ISqlFormatterAlignmentElem_getAlignmentElemGroupsFromRightElem
    Debug.Assert groups.Count = 2
    Set group = groups.Item(0)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is multiCondi
    Set group = groups.Item(1)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is multiCondi2
End Sub

' 测试: 设置当前条件不是整个区域中的唯一一个条件
Private Sub test_ISqlFormatterCondition_setNotOnlyOneCondition()
    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef
    Dim g As SqlFormatterTwoElemCondition

    ' ==============================
    ' 1. 单行 + 没有逻辑运算符 -- 不设置 -- 没有前缀空格
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 <= x2"

    ' ==============================
    ' 2. 单行 + 没有逻辑运算符 -- 设置   -- 有前缀空格
    ' ==============================
    g.ISqlFormatterCondition_setNotOnlyOneCondition
    Debug.Assert g.ISqlFormatterElem_toString(config) = "    x1 <= x2"

    ' ==============================
    ' 3. 单行 + 逻辑运算符 -- 不设置 -- 没有前缀空格
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置 and
    g.ISqlFormatterCondition_setLogicOperator getAndToken
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterElem_toString(config) = "and x1 <= x2"

    ' ==============================
    ' 4. 单行 + 逻辑运算符 -- 设置   -- 没有前缀空格
    ' ==============================
    g.ISqlFormatterCondition_setNotOnlyOneCondition
    Debug.Assert g.ISqlFormatterElem_toString(config) = "and x1 <= x2"

    ' ==============================
    ' 多行 + 没有逻辑运算符 -- 不设置 -- 没有前缀空格
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素 (多行元素)
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素 (单行元素)
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<= x2"

    ' ==============================
    ' 多行 + 没有逻辑运算符 -- 设置   -- 有前缀空格
    ' ==============================
    g.ISqlFormatterCondition_setNotOnlyOneCondition

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "    col1,"
    Debug.Assert strArr.Item(1) = "    col2"
    Debug.Assert strArr.Item(2) = "    <= x2"

    ' ==============================
    ' 多行 + 逻辑运算符 -- 不设置 -- 没有前缀空格
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置 and
    g.ISqlFormatterCondition_setLogicOperator getAndToken
    ' 设置第一个元素 (多行元素)
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素 (单行元素)
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "and col1,"
    Debug.Assert strArr.Item(1) = "    col2"
    Debug.Assert strArr.Item(2) = "    <= x2"

    ' ==============================
    ' 多行 + 逻辑运算符 -- 设置   -- 有前缀空格
    ' ==============================
    g.ISqlFormatterCondition_setNotOnlyOneCondition

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "and col1,"
    Debug.Assert strArr.Item(1) = "    col2"
    Debug.Assert strArr.Item(2) = "    <= x2"
End Sub

' ======================================================================
' ISqlFormatterElem 接口实现测试
' ======================================================================
' 测试: addComponent 方法
Private Sub test_ISqlFormatterElem_addComponent()
    ' 在其他方法中测试，这里不再单独做测试
End Sub

' 测试: addComponentToFirst 方法
Private Sub test_ISqlFormatterElem_addComponentToFirst()
    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim g As SqlFormatterTwoElemCondition

    ' ==============================
    ' 1. 测试
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    ' 从左侧添加第一个元素
    g.ISqlFormatterElem_addComponentToFirst getStrNameToken("x1")

    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 <= x2"
End Sub

' 测试: canAddComponentToFirst 方法
Private Sub test_ISqlFormatterElem_canAddComponentToFirst()
    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    ' ==============================
    ' 1. 只添加普通元素
    ' ==============================
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator

    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = True

    ' ==============================
    ' 2. 只设置左边界括号: false
    ' ==============================
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = False

    ' ==============================
    ' 3. 只设置右边界括号: True
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addBoundaryRightParenthesis
    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = True

    ' ==============================
    ' 4. 设置左 + 右边界括号: false
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    g.ISqlFormatterElem_addBoundaryRightParenthesis
    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = False

    ' ==============================
    ' 5. 设置普通元素后，设置逻辑运算符
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = True

    ' 添加逻辑运算符
    g.ISqlFormatterCondition_setLogicOperator getAndToken
    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = True

End Sub

' 测试: getAlignmentElemGroups 方法
Private Sub test_ISqlFormatterElem_getAlignmentElemGroups()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim groups As IObjArrayRef
    Dim group As IObjArrayRef

    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")

    ' ==============================
    ' 2. 测试
    ' ==============================
    Set groups = g.ISqlFormatterElem_getAlignmentElemGroups
    Debug.Assert groups.Count = 1
    Set group = groups.Item(0)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is g
End Sub

' 测试: setElemNestCount 方法
Private Sub test_ISqlFormatterElem_setElemNestCount()

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration
    ' 通过这个设置，是的 test_ISqlFormatterElem_setElemNestCount 对右侧元素的设置生效
    config.alignmentLevel = SqlAlignmentLevel.NO_ALIGNMENT

    Dim g As SqlFormatterTwoElemCondition
    Dim singleLineCondi As SqlFormatterTwoElemCondition
    Dim multiLineCondi As SqlFormatterTwoElemCondition
    Dim multiLineCondi2 As SqlFormatterTwoElemCondition

    ' ==============================
    ' 1. 单行元素 + 单行条件
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素: 单行条件
    Set singleLineCondi = New SqlFormatterTwoElemCondition
    singleLineCondi.ISqlFormatterElem_addComponent getStrNameToken("y1")
    singleLineCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    singleLineCondi.ISqlFormatterElem_addComponent getStrNameToken("y2")
    g.ISqlFormatterElem_addComponent singleLineCondi

    g.ISqlFormatterElem_setElemNestCount 2, config

    '     V 到这里
    ' x1 <= y1 <= y2
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 13 ' 8 + 5
    '           V 到这里
    ' x1 <= y1 <= y2
    Debug.Assert singleLineCondi.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 19 ' 8 + 11

    ' ==============================
    ' 2. 多行条件 + 单行条件
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素: 多行条件
    Set multiLineCondi = New SqlFormatterTwoElemCondition
    multiLineCondi.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiLineCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiLineCondi.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_addComponent multiLineCondi
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素: 单行条件
    Set singleLineCondi = New SqlFormatterTwoElemCondition
    singleLineCondi.ISqlFormatterElem_addComponent getStrNameToken("y1")
    singleLineCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    singleLineCondi.ISqlFormatterElem_addComponent getStrNameToken("y2")
    g.ISqlFormatterElem_addComponent singleLineCondi

    ' 设置前缀空格数
    g.ISqlFormatterElem_setElemNestCount 2, config ' 8 个空格

    ' col1,
    ' col2
    ' <= x2
    ' <= y1 <= y2
    '        ^ 到这里
    Debug.Assert singleLineCondi.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 16 ' 8 + 8

    ' ==============================
    ' 3. 多行条件 + 多行行条件
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素: 多行条件
    Set multiLineCondi = New SqlFormatterTwoElemCondition
    multiLineCondi.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiLineCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiLineCondi.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_addComponent multiLineCondi
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素: 单行条件
    Set multiLineCondi2 = New SqlFormatterTwoElemCondition
    multiLineCondi2.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiLineCondi2.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiLineCondi2.ISqlFormatterElem_addComponent getStrNameToken("x2")
    g.ISqlFormatterElem_addComponent multiLineCondi2

    ' 设置前缀空格数
    g.ISqlFormatterElem_setElemNestCount 2, config ' 8 个空格

    Dim strArr As IPrimitiveArrayRef
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 7
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<= x2"
    Debug.Assert strArr.Item(3) = "<="
    Debug.Assert strArr.Item(4) = "col1,"
    Debug.Assert strArr.Item(5) = "col2"
    Debug.Assert strArr.Item(6) = "<= x2"

End Sub

' 测试: setPrefixSpaceCount 方法
Private Sub test_ISqlFormatterElem_setPrefixSpaceCount()

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration
    ' 通过这个设置，是的 test_ISqlFormatterElem_setElemNestCount 对右侧元素的设置生效
    config.alignmentLevel = SqlAlignmentLevel.NO_ALIGNMENT

    Dim g As SqlFormatterTwoElemCondition
    Dim singleLineCondi As SqlFormatterTwoElemCondition
    Dim multiLineCondi As SqlFormatterTwoElemCondition
    Dim multiLineCondi2 As SqlFormatterTwoElemCondition

    ' ==============================
    ' 1. 单行元素 + 单行条件
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素: 单行条件
    Set singleLineCondi = New SqlFormatterTwoElemCondition
    singleLineCondi.ISqlFormatterElem_addComponent getStrNameToken("y1")
    singleLineCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    singleLineCondi.ISqlFormatterElem_addComponent getStrNameToken("y2")
    g.ISqlFormatterElem_addComponent singleLineCondi

    g.ISqlFormatterElem_setPrefixSpaceCount 8, config

    '     V 到这里
    ' x1 <= y1 <= y2
    Debug.Assert g.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 13 ' 8 + 5
    '           V 到这里
    ' x1 <= y1 <= y2
    Debug.Assert singleLineCondi.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 19 ' 8 + 11

    ' ==============================
    ' 2. 多行条件 + 单行条件
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素: 多行条件
    Set multiLineCondi = New SqlFormatterTwoElemCondition
    multiLineCondi.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiLineCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiLineCondi.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_addComponent multiLineCondi
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素: 单行条件
    Set singleLineCondi = New SqlFormatterTwoElemCondition
    singleLineCondi.ISqlFormatterElem_addComponent getStrNameToken("y1")
    singleLineCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    singleLineCondi.ISqlFormatterElem_addComponent getStrNameToken("y2")
    g.ISqlFormatterElem_addComponent singleLineCondi

    ' 设置前缀空格数
    g.ISqlFormatterElem_setPrefixSpaceCount 8, config ' 8 个空格

    ' col1,
    ' col2
    ' <= x2
    ' <= y1 <= y2
    '        ^ 到这里
    Debug.Assert singleLineCondi.ISqlFormatterAlignmentElem_getAlignmentSize(config) = 16 ' 8 + 8

    ' ==============================
    ' 3. 多行条件 + 多行行条件
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置第一个元素: 多行条件
    Set multiLineCondi = New SqlFormatterTwoElemCondition
    multiLineCondi.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiLineCondi.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiLineCondi.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_addComponent multiLineCondi
    ' 设置条件运算符 <=
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    ' 设置第二个元素: 单行条件
    Set multiLineCondi2 = New SqlFormatterTwoElemCondition
    multiLineCondi2.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    multiLineCondi2.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    multiLineCondi2.ISqlFormatterElem_addComponent getStrNameToken("x2")
    g.ISqlFormatterElem_addComponent multiLineCondi2

    ' 设置前缀空格数
    g.ISqlFormatterElem_setPrefixSpaceCount 8, config ' 8 个空格

    Dim strArr As IPrimitiveArrayRef
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 7
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<= x2"
    Debug.Assert strArr.Item(3) = "<="
    Debug.Assert strArr.Item(4) = "col1,"
    Debug.Assert strArr.Item(5) = "col2"
    Debug.Assert strArr.Item(6) = "<= x2"
End Sub

' 测试: hasBoundaryParenthesis 方法
Private Sub test_ISqlFormatterElem_hasBoundaryParenthesis()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 测试
    ' ==============================
    ' 2. 增加左边界括号
    elem.addBoundaryLeftParenthesis
    Debug.Assert elem.hasBoundaryParenthesis = True

    ' 3. 增加右边界括号
    elem.addBoundaryRightParenthesis
    Debug.Assert elem.hasBoundaryParenthesis = True

    ' 4. 重新创建对象，并只添加右边界括号
    Set g = New SqlFormatterTwoElemCondition
    Set elem = g

    elem.addComponent getTableNameToken
    Debug.Assert elem.hasBoundaryParenthesis = False

    '    增加右边界括号
    elem.addBoundaryRightParenthesis
    Debug.Assert elem.hasBoundaryParenthesis = True
End Sub

' 测试: addBoundaryLeftParenthesis 方法
Private Sub test_ISqlFormatterElem_addBoundaryLeftParenthesis()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef

    ' ==============================
    ' 2. 添加一个左括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    Debug.Assert g.ISqlFormatterElem_toString(config) = "(" & "x1 <= x2"

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "(" & "x1 <= x2"

    ' ==============================
    ' 3. 添加多个左括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryLeftParenthesis(3)
    Debug.Assert g.ISqlFormatterElem_toString(config) = "((((" & "x1 <= x2"

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "((((" & "x1 <= x2"
End Sub

' 测试: addBoundaryRightParenthesis 方法
Private Sub test_ISqlFormatterElem_addBoundaryRightParenthesis()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef

    ' ==============================
    ' 3. 添加一个右括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryRightParenthesis
    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 <= x2" & ")"

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "x1 <= x2" & ")"

    ' ==============================
    ' 4. 添加多个右括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryRightParenthesis(3)
    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 <= x2" & "))))"

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "x1 <= x2" & "))))"
End Sub

' 测试: getType 方法
Private Sub test_ISqlFormatterElem_getType()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 默认没有类型
    ' ==============================
    Debug.Assert elem.getType = SqlTokenType.NO_MEAN

    ' ==============================
    ' 3. 添加一个元素后，也没有类型
    ' ==============================
    elem.addComponent getTableNameToken
    Debug.Assert elem.getType = SqlTokenType.NO_MEAN
End Sub

' 测试: isComment 方法
Private Sub test_ISqlFormatterElem_isComment()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    Dim elem As ISqlFormatterElem
    Set elem = g
    ' ==============================
    ' 2. 默认为 false
    ' ==============================
    Debug.Assert elem.isComment = False

    ' ==============================
    ' 3. 即使添加一个注释，也是 false
    ' ==============================
    elem.addComponent getShareLineCommentToken
    Debug.Assert elem.isComment = False

    elem.addComponent getSingleLineCommentToken
    Debug.Assert elem.isComment = False
End Sub

' 测试: isShareLineComment 方法
Private Sub test_ISqlFormatterElem_isShareLineComment()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 默认为 false
    ' ==============================
    Debug.Assert elem.isShareLineComment = False

    ' ==============================
    ' 3. 即使添加一个注释，也是 false
    ' ==============================
    elem.addComponent getShareLineCommentToken
    Debug.Assert elem.isShareLineComment = False

    elem.addComponent getSingleLineCommentToken
    Debug.Assert elem.isShareLineComment = False
End Sub

' 测试: isSingleLineComment 方法
Private Sub test_ISqlFormatterElem_isSingleLineComment()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 默认为 false
    ' ==============================
    Debug.Assert elem.isShareLineComment = False

    ' ==============================
    ' 3. 即使添加一个注释，也是 false
    ' ==============================
    elem.addComponent getShareLineCommentToken
    Debug.Assert elem.isSingleLineComment = False

    elem.addComponent getSingleLineCommentToken
    Debug.Assert elem.isSingleLineComment = False
End Sub

' 测试: isEndsWithComment 方法
Private Sub test_ISqlFormatterElem_isEndsWithComment()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterTwoElemCondition
    Set g = New SqlFormatterTwoElemCondition

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 默认为 false
    ' ==============================
    Debug.Assert elem.isEndsWithComment = False

    ' ==============================
    ' 3. 测试
    ' ==============================
    ' 1. 添加一个元素
    elem.addComponent getTableNameToken
    Debug.Assert elem.isEndsWithComment = False

    ' 2. 添加一个和前一个元素同一行的注释
    elem.addComponent getShareLineCommentToken
    Debug.Assert elem.isEndsWithComment = True

    ' 3. 再添加一个非注释元素
    elem.addComponent getTableNameToken
    Debug.Assert elem.isEndsWithComment = False

    ' 4. 添加一个单行注释
    elem.addComponent getSingleLineCommentToken
    Debug.Assert elem.isEndsWithComment = True

    ' 5. 添加左括号 --> 仍然是以注释结尾的
    elem.addBoundaryLeftParenthesis
    Debug.Assert elem.isEndsWithComment = True

    ' 6. 添加右括号 --> 不是以注释结尾的
    elem.addBoundaryRightParenthesis
    Debug.Assert elem.isEndsWithComment = False
End Sub

' 测试: isMultiLine 方法
Private Sub test_ISqlFormatterElem_isMultiLine()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterTwoElemCondition

    Dim elem As ISqlFormatterElem

    ' ==============================
    ' 2. 左侧添加一个多行元素
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True

    ' ==============================
    ' 3. 在条件运算符右侧添加一个多行元素
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False

    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True

    ' ==============================
    ' 4. 单行元素 + 同一行的注释 + 无边界括号: False
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    Set elem = g
    elem.addComponent getStrNameToken("x1")
    elem.addComponent getShareLineCommentToken
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False

    ' ==============================
    ' 5. 单行元素 + 同一行的注释 + 有边界括号: True
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterElem_addComponent getShareLineCommentToken
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True

    ' ==============================
    ' 6. 左侧单行元素 + 单行注释: True
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getSingleLineCommentToken
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True

    ' ==============================
    ' 7. 右侧单行元素 + 单行注释: True
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False
    g.ISqlFormatterElem_addComponent getSingleLineCommentToken
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True

    ' ==============================
    ' 8. 测试: 从左侧增加注释
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 从左侧添加一个单行注释
    g.ISqlFormatterElem_addComponentToFirst getSingleLineCommentToken
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False

    g.ISqlFormatterElem_addComponentToFirst getStrNameToken("x1")
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True
End Sub

' 测试: toString + toStringArray 方法
Private Sub test_ISqlFormatterElem_toString_toStringArray()
    Dim g As SqlFormatterTwoElemCondition
    Dim strArr As IPrimitiveArrayRef

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim prefixSpace As String
    prefixSpace = "    "

    ' ==================================================
    ' 1. 单行测试
    ' ==================================================
    ' ==============================
    ' 1.1. 单行无边界括号
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 <= x2"
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "x1 <= x2"

    ' ==============================
    ' 1.2. 单行 + 左边界括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryLeftParenthesis 2
    Debug.Assert g.ISqlFormatterElem_toString(config) = "((x1 <= x2"
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "((x1 <= x2"

    ' ==============================
    ' 1.3. 单行 + 左右边界括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryRightParenthesis 2
    Debug.Assert g.ISqlFormatterElem_toString(config) = "((x1 <= x2))"
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "((x1 <= x2))"

    ' ==============================
    ' 1.4. 单行 + 右边界括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryLeftParenthesis -2 ' 这里通过负数参数来清除左括号

    ' 这里继续使用前面设置的右边界括号
    Debug.Assert g.ISqlFormatterElem_toString(config) = "x1 <= x2))"
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "x1 <= x2))"

    ' ==================================================
    ' 2.多单行测试
    ' ==================================================
    ' ==============================
    ' 2.1. 多行无边界括号
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<= x2"

    ' ==============================
    ' 2.2. 多行 + 左边界括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryLeftParenthesis 2
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 4
    Debug.Assert strArr.Item(0) = "(("
    Debug.Assert strArr.Item(1) = prefixSpace & "col1,"
    Debug.Assert strArr.Item(2) = prefixSpace & "col2"
    Debug.Assert strArr.Item(3) = prefixSpace & "<= x2"

    ' ==============================
    ' 2.3. 多行 + 左右边界括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryRightParenthesis 2
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 5
    Debug.Assert strArr.Item(0) = "(("
    Debug.Assert strArr.Item(1) = prefixSpace & "col1,"
    Debug.Assert strArr.Item(2) = prefixSpace & "col2"
    Debug.Assert strArr.Item(3) = prefixSpace & "<= x2"
    Debug.Assert strArr.Item(4) = "))"

    ' ==============================
    ' 2.4. 多行 + 右边界括号
    ' ==============================
    g.ISqlFormatterElem_addBoundaryLeftParenthesis -2 ' 这里通过负数参数来清除左括号

    ' 这里继续使用前面设置的右边界括号
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 4
    Debug.Assert strArr.Item(0) = prefixSpace & "col1,"
    Debug.Assert strArr.Item(1) = prefixSpace & "col2"
    Debug.Assert strArr.Item(2) = prefixSpace & "<= x2"
    Debug.Assert strArr.Item(3) = "))"


    ' ==================================================
    ' 5. 特殊case: 左括号 + 一个同行注释 + 条件内容
    ' ==================================================
    Set g = New SqlFormatterTwoElemCondition
    ' 1. 左括号
    g.ISqlFormatterElem_addBoundaryLeftParenthesis 2
    ' 2. 添加一个和前一个元素同一行的注释
    g.ISqlFormatterElem_addComponent getShareLineCommentToken
    ' 3. 条件内容
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    ' 4. 检查结果
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "(( --aaaaaa"
    Debug.Assert strArr.Item(1) = "    x1 <= x2"

    ' ==============================
    ' 6. and 逻辑运算符 + 两个多行元素
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    ' 设置 and
    g.ISqlFormatterCondition_setLogicOperator getAndToken

    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 5
    Debug.Assert strArr.Item(0) = "and col1,"
    Debug.Assert strArr.Item(1) = "    col2"
    Debug.Assert strArr.Item(2) = "    <="
    Debug.Assert strArr.Item(3) = "    col1,"
    Debug.Assert strArr.Item(4) = "    col2"

    ' ==============================
    ' 7. 只有左侧元素 + 边界括号，并且左侧元素是多行的
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition

    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    g.ISqlFormatterElem_addBoundaryRightParenthesis

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 4
    Debug.Assert strArr.Item(0) = "("
    Debug.Assert strArr.Item(1) = "    col1,"
    Debug.Assert strArr.Item(2) = "    col2"
    Debug.Assert strArr.Item(3) = ")"

    ' ==============================
    ' 8. 只有左侧元素 + 边界括号，并且左侧元素是单行的
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition

    ' 设置第一个元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    g.ISqlFormatterElem_addBoundaryRightParenthesis

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "(x1)"

    ' ==============================
    ' 9. 一个单行元素 + 一个条件运算符 + 一个同行注释 + 一个单行元素
    '    测试: 左侧是单行的，右侧是多行的，并且条件运算符后面的同行注释可以被吸收到条件运算符的后面
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent createShareLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "x1 <= --c1"
    Debug.Assert strArr.Item(1) = "      x2"

    ' ==============================
    ' 10. 一个单行元素 + 一个条件运算符 + 一个单行注释 + 一个单行元素
    '    测试: 左侧是单行的，右侧是多行的，并且条件运算符后面的单行注释可以被吸收
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent createSingleLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "x1 <="
    Debug.Assert strArr.Item(1) = "      --c1"
    Debug.Assert strArr.Item(2) = "      x2"

    ' ==============================
    ' 11. 一个单行元素 + 一个条件运算符 + 一个同行注释 + 一个多行元素
    '    测试: 左侧是单行的，右侧是多行的，并且条件运算符后面的同行注释可以被吸收到条件运算符的后面
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent createShareLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "x1 <= --c1"
    Debug.Assert strArr.Item(1) = "      col1,"
    Debug.Assert strArr.Item(2) = "      col2"

    ' ==============================
    ' 12. 一个单行元素 + 一个条件运算符 + 一个单行注释 + 一个多行元素
    '    测试: 左侧是单行的，右侧是多行的，并且条件运算符后面的单行注释可以被吸收
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent createSingleLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 4
    Debug.Assert strArr.Item(0) = "x1 <="
    Debug.Assert strArr.Item(1) = "      --c1"
    Debug.Assert strArr.Item(2) = "      col1,"
    Debug.Assert strArr.Item(3) = "      col2"

    ' ==============================
    ' 13. 一个多行元素 + 一个条件运算符 + 一个同行注释 + 一个单行元素
    '    测试: 左侧是单行的，右侧是多行的，并且条件运算符后面的同行注释可以被吸收到条件运算符的后面
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent createShareLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 4
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<= --c1"
    Debug.Assert strArr.Item(3) = "x2"

    ' ==============================
    ' 14. 一个多行元素 + 一个条件运算符 + 一个单行注释 + 一个单行元素
    '    测试: 左侧是单行的，右侧是多行的，并且条件运算符后面的单行注释可以被吸收
    ' ==============================
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent createSingleLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 5
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<="
    Debug.Assert strArr.Item(3) = "--c1"
    Debug.Assert strArr.Item(4) = "x2"

    ' ==============================
    ' 15. 一个多行元素 + 一个条件运算符 + 一个同行注释 + 一个多行元素
    '    测试: 左侧是单行的，右侧是多行的，并且条件运算符后面的同行注释可以被吸收到条件运算符的后面
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent createShareLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 5
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<= --c1"
    Debug.Assert strArr.Item(3) = "col1,"
    Debug.Assert strArr.Item(4) = "col2"

    ' ==============================
    ' 12. 一个多行元素 + 一个条件运算符 + 一个单行注释 + 一个多行元素
    '    测试: 左侧是单行的，右侧是多行的，并且条件运算符后面的单行注释可以被吸收
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent createSingleLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesis

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 6
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2"
    Debug.Assert strArr.Item(2) = "<="
    Debug.Assert strArr.Item(3) = "--c1"
    Debug.Assert strArr.Item(4) = "col1,"
    Debug.Assert strArr.Item(5) = "col2"

    ' ==============================
    ' 13. and + 一个同行注释 + STR_NAME + <= + STR_NAME
    '    测试: and 和后面的同行注释之间只有一个空格
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterCondition_setLogicOperator getAndToken
    g.ISqlFormatterElem_addComponent createShareLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "and --c1"
    Debug.Assert strArr.Item(1) = "    x1 <= x2"

    ' ==============================
    ' 14. and + 一个单行注释 + STR_NAME + <= + STR_NAME
    '    测试: and 后面没有空格
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterCondition_setLogicOperator getAndToken
    g.ISqlFormatterElem_addComponent createSingleLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "and"
    Debug.Assert strArr.Item(1) = "    --c1"
    Debug.Assert strArr.Item(2) = "    x1 <= x2"

    ' ==============================
    ' 15. or + 一个同行注释 + STR_NAME + <= + STR_NAME
    '    测试: or 和后面的同行注释之间有只有两个空格
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterCondition_setLogicOperator getOrToken
    g.ISqlFormatterElem_addComponent createShareLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "or  --c1"
    Debug.Assert strArr.Item(1) = "    x1 <= x2"

    ' ==============================
    ' 16. or + 一个单行注释 + STR_NAME + <= + STR_NAME
    '    测试: or 后面没有空格
    ' ==============================
    ' 1. 基础测试
    Set g = New SqlFormatterTwoElemCondition
    g.ISqlFormatterCondition_setLogicOperator getOrToken
    g.ISqlFormatterElem_addComponent createSingleLineCommentToken("--c1")
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    g.ISqlFormatterCondition_setConditionOperator getLeConditionOperator
    g.ISqlFormatterElem_addComponent getStrNameToken("x2")

    g.ISqlFormatterElem_setPrefixSpaceCount 0, config
    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 3
    Debug.Assert strArr.Item(0) = "or"
    Debug.Assert strArr.Item(1) = "    --c1"
    Debug.Assert strArr.Item(2) = "    x1 <= x2"

End Sub